package com.ourteam.system.api;

import com.ourteam.frame.web.AbstractTreeBuilder;
import com.ourteam.frame.web.ITreeNodeBuilder;
import com.ourteam.frame.web.TreeViewNodeBean;
import com.ourteam.system.domain.ApplicationDomain;
import com.ourteam.system.domain.SystemAction;
import com.ourteam.system.domain.SystemModule;


public class SystemAppModuleTreeBuilder extends AbstractTreeBuilder {

	private long domainId;

	public SystemAppModuleTreeBuilder(long domainId) {
		super();
		this.domainId = domainId;
	}

	public long getDomainId() {
		return domainId;
	}

	public void setDomainId(long domainId) {
		this.domainId = domainId;
	}

	@Override
	protected String getTreeConfigFile() {
		return "classpath:ui/system/sys_function.tree";
	}

	protected TreeViewNodeBean configTreeViewNodeProperties(Object obj, TreeViewNodeBean treeViewNodeBean) {

		if (obj instanceof ApplicationDomain) {
			treeViewNodeBean.setActionGroupId("sysDomainNodeActionGroup");
		} else if (obj instanceof SystemModule) {
			treeViewNodeBean.setTags(new String[] { ((SystemModule) obj).getModuleCode() });
		} else if (obj instanceof SystemAction) {
			treeViewNodeBean.setTags(new String[] { ((SystemAction) obj).getActionCode() });
		}

		return treeViewNodeBean;
	}

	@Override
	protected void initTreeNodeBuilder(ITreeNodeBuilder treeNodeBuilder) throws Exception {
		if (treeNodeBuilder instanceof SystemDomainNodeBuilder) {
			((SystemDomainNodeBuilder) treeNodeBuilder).setDomainId(domainId);
		}
	}

}
